package com.rest.demo.io;

import java.io.*;

/**
 * @author Administrator
 * @decription 文件合并
 * @Date 2018-02-05 15:56
 */
public class SequenceInputStreamDemo {


    public static void main(String[] args) {
        InputStream is1 = null;
        InputStream is2 = null;
        OutputStream os = null;
        SequenceInputStream sequenceInputStream = null;
        try {
            is1 = new FileInputStream("F:\\a.txt");
            is2 = new FileInputStream("F:\\out.txt");
            os = new FileOutputStream("F:\\a-out.txt");
            sequenceInputStream = new SequenceInputStream(is1,is2);
            int b = -1;
            byte[] buff = new byte[1024];
            while((b = sequenceInputStream.read(buff)) != -1) {
                os.write(buff,0,b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is1.close();
                is2.close();
                sequenceInputStream.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
